package singleStackProgrammingQuizSubmission

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("POST")
        url("/api/single-stack-programming-quiz-submissions")
        headers {
            contentType(applicationJsonUtf8())
        }
        body("""
            {
                "userAnswerRepo":"http://github.com/test/test",
                "branch":"master",
                "quizId":1,
                "assignmentId":1,
                "studentId":1
            }
        """)
        bodyMatchers {
            jsonPath('$.userAnswerRepo', byRegex("[\\s\\S]+"))
            jsonPath('$.branch', byRegex("[\\s\\S]+"))
            jsonPath('$.quizId', byRegex(number()))
            jsonPath('$.assignmentId', byRegex(number()))
            jsonPath('$.studentId', byRegex(number()))
        }
    }
    response {
        status(201)
        body("""
        {
            "id":1,
            "assignmentId":1,
            "quizId":1,
            "userId":1,
            "userAnswer":"http://github.com/test/test",
            "submitTime":1,
            "status":null,
            "result":"SUCCESS",
            "answerBranch":"master",
            "buildNumber":null,
            "commitId":null
        }
        """)
        bodyMatchers {
            jsonPath('$.id', byRegex(number()))
            jsonPath('$.assignmentId', byRegex(number()))
            jsonPath('$.quizId', byRegex(number()))
            jsonPath('$.userId', byRegex(number()))
            jsonPath('$.userAnswer', byRegex("[\\s\\S]+"))
            jsonPath('$.submitTime', byRegex("[\\s\\S]+"))
            jsonPath('$.status', byCommand('org.junit.Assert.assertNull($it)'))
            jsonPath('$.result', byRegex("[\\s\\S]+"))
            jsonPath('$.answerBranch', byRegex("[\\s\\S]+"))
            jsonPath('$.buildNumber', byCommand('org.junit.Assert.assertNull($it)'))
            jsonPath('$.commitId', byCommand('org.junit.Assert.assertNull($it)'))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}
